package com.sks.web.action.deployment;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.springframework.stereotype.Controller;

import com.sks.bean.PageView;
import com.sks.bean.QueryResult;
import com.sks.bean.pojo.Metro;
import com.sks.bean.pojo.MetroStation;
import com.sks.service.house.MetroService;
import com.sks.utils.SiteUrl;
import com.sks.utils.StringUtil;
import com.sks.web.action.BasicAction;
import com.sks.web.formbean.house.MetroForm;

import flexjson.JSONSerializer;

@Controller("/sks/frontpages/privilege/deployment/station")
public class StationAction extends BasicAction {
	@Resource(name = "metroServiceBean")
	private MetroService metroService;

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 * @description 根据地铁线来获取地铁站名
	 * @update 2012-3-11 上午11:16:14
	 */
	public ActionForward getStations(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		MetroForm formbean = (MetroForm) form;
		if (null == formbean.getMetroId() || 0 == formbean.getMetroId()) {
			response.getWriter().write("[{\"name\":\"\",\"areaId\":\"\"}]");
			return null;
		}
		Metro topMetro = metroService.find(formbean.getMetroId());
		List<MetroStation> mss = topMetro.getMetroStationsForMetroId();
		JSONSerializer json = new JSONSerializer();
		String jsonStr = json.exclude("*.class", "metroByMetroId", "metroByMetroId1",
				"isIntersect", "remark", "metroId", "metroId1").include("stationId", "name").serialize(mss);
		response.getWriter().write(jsonStr);
		return null;
	}
}